package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RequestMapping("/user")
@RestController
public class UserConrtoller {


    @Autowired
    private UserService userService;

    @PostMapping
    public PageResult page(@RequestBody PageQuery<User> pageQuery){
        PageResult pageResult = userService.page(pageQuery);
        return pageResult;
    }

    /***
     * 登录
     * 1)接收参数
     * 2)查询数据库对应账号密码的用户
     * 3)查得到，登录成功，生成令牌，并颁发令牌
     * 4)查不到，登录失败，提示错误信息
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        UserLoginVo vo = userService.login(user);

        Result result = new Result();
        if(vo==null){
            result.setMsg("账号或密码错误");
            result.setCode(404);
            return result;
        }
        //响应结果封装

        result.setData(vo);
        result.setCode(200);
        return result;
    }











}
